unit uKeyboardMouse;

interface

uses Windows, IniFiles, SysUtils;



type
    THotKey = class(TObject)
    private
        procedure PushButton (Key: byte);
        procedure PushAltButton (Key: byte);
        procedure DecodeKey (s: string);
    public
        constructor create;
        destructor destroy;
        procedure ActionToKey (atAction: byte);
        procedure MouseClick (X,Y:Cardinal);
    end;

implementation

uses fMain, uConstants, uMainData;

constructor THotKey.Create;
begin
    inherited;
end;


destructor THotKey.Destroy;
begin
    inherited;
end;

procedure THotKey.PushButton (Key: byte);
begin
    keybd_event(Key,0,0,0);
    keybd_event(Key,0,KEYEVENTF_KEYUP,0);
end;

procedure THotKey.MouseClick (X,Y:Cardinal);
begin
    SetCursorPos(x,y);
    Mouse_Event(MOUSEEVENTF_LEFTDOWN, X, Y, 0, 0);
    Mouse_Event(MOUSEEVENTF_LEFTUP, X, Y, 0, 0);
end;

procedure THotKey.ActionToKey (atAction: byte);
begin
    case atAction of
        atDrinkGCP     : DecodeKey(Main.ComboBox3.Text);
        atDrinkBCP     : DecodeKey(Main.ComboBox4.Text);
        atDrinkLHP     : DecodeKey(Main.ComboBox5.Text);
        atDrinkWHP     : DecodeKey(Main.ComboBox6.Text);
        atDrinkQHP     : DecodeKey(Main.ComboBox7.Text);
        atDrinkBHP     : DecodeKey(Main.ComboBox8.Text);
        atDrinkMP      : DecodeKey(Main.ComboBox9.Text);
        atAttack       : DecodeKey(Main.ComboBox1.Text);
        atChangeTarget : DecodeKey(Main.ComboBox2.Text);
        atBSOE         : DecodeKey(Main.ComboBox12.Text);
        atPetFood      : DecodeKey(Main.ComboBox11.Text);
        12             : DecodeKey(Main.ComboBox13.Text);
        13             : DecodeKey(Main.ComboBox14.Text);
        14             : DecodeKey(Main.ComboBox15.Text);
        15             : DecodeKey(Main.ComboBox16.Text);
        16             : DecodeKey(Main.ComboBox17.Text);
        17             : DecodeKey(Main.ComboBox18.Text);
        18             : DecodeKey(Main.ComboBox19.Text);
        19             : DecodeKey(Main.ComboBox20.Text);
        20             : DecodeKey(Main.ComboBox21.Text);
        21             : DecodeKey(Main.ComboBox22.Text);
        22             : DecodeKey(Main.ComboBox23.Text);
        23             : DecodeKey(Main.ComboBox24.Text);
        255            : PushButton(VK_UP);
    end;
end;

procedure THotKey.DecodeKey (s: string);
var
    code: byte;
begin
    if s = '' then exit;
    
    if pos('Alt', s) > 0 then
    begin
        PushAltButton (VkKeyScan(copy (s,5,1)[1]));
    end
    else
    begin
        if length(s) = 3 then s := s[2] + s[3]
            else s := s[2];
        code := StrToInt(s) + 111;
        PushButton (code);
    end;
end;

procedure THotKey.PushAltButton (Key: byte);
begin
    keybd_event(18, MapVirtualKey(18, 0), 0, 0);
    keybd_event(Key,0,0,0);
    keybd_event(Key,0,KEYEVENTF_KEYUP,0);
    keybd_event(18, MapVirtualKey(18, 0), KEYEVENTF_KEYUP, 0);

end;

end.
